<?php


abstract class BaseCuenta extends BaseObject  implements Persistent {


	
	protected static $peer;


	
	protected $id;


	
	protected $cliente_id;


	
	protected $porc_comision = 0;


	
	protected $descuento = 0;


	
	protected $cuenta;


	
	protected $sucursal;


	
	protected $banco;


	
	protected $comision = 0;

	
	protected $alreadyInSave = false;

	
	protected $alreadyInValidation = false;

	
	public function getId()
	{

		return $this->id;
	}

	
	public function getClienteId()
	{

		return $this->cliente_id;
	}

	
	public function getPorcComision()
	{

		return $this->porc_comision;
	}

	
	public function getDescuento()
	{

		return $this->descuento;
	}

	
	public function getCuenta()
	{

		return $this->cuenta;
	}

	
	public function getSucursal()
	{

		return $this->sucursal;
	}

	
	public function getBanco()
	{

		return $this->banco;
	}

	
	public function getComision()
	{

		return $this->comision;
	}

	
	public function setId($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->id !== $v) {
			$this->id = $v;
			$this->modifiedColumns[] = CuentaPeer::ID;
		}

	} 
	
	public function setClienteId($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->cliente_id !== $v) {
			$this->cliente_id = $v;
			$this->modifiedColumns[] = CuentaPeer::CLIENTE_ID;
		}

	} 
	
	public function setPorcComision($v)
	{

		if ($this->porc_comision !== $v || $v === 0) {
			$this->porc_comision = $v;
			$this->modifiedColumns[] = CuentaPeer::PORC_COMISION;
		}

	} 
	
	public function setDescuento($v)
	{

		if ($this->descuento !== $v || $v === 0) {
			$this->descuento = $v;
			$this->modifiedColumns[] = CuentaPeer::DESCUENTO;
		}

	} 
	
	public function setCuenta($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->cuenta !== $v) {
			$this->cuenta = $v;
			$this->modifiedColumns[] = CuentaPeer::CUENTA;
		}

	} 
	
	public function setSucursal($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->sucursal !== $v) {
			$this->sucursal = $v;
			$this->modifiedColumns[] = CuentaPeer::SUCURSAL;
		}

	} 
	
	public function setBanco($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->banco !== $v) {
			$this->banco = $v;
			$this->modifiedColumns[] = CuentaPeer::BANCO;
		}

	} 
	
	public function setComision($v)
	{

		if ($this->comision !== $v || $v === 0) {
			$this->comision = $v;
			$this->modifiedColumns[] = CuentaPeer::COMISION;
		}

	} 
	
	public function hydrate(ResultSet $rs, $startcol = 1)
	{
		try {

			$this->id = $rs->getInt($startcol + 0);

			$this->cliente_id = $rs->getInt($startcol + 1);

			$this->porc_comision = $rs->getFloat($startcol + 2);

			$this->descuento = $rs->getFloat($startcol + 3);

			$this->cuenta = $rs->getString($startcol + 4);

			$this->sucursal = $rs->getString($startcol + 5);

			$this->banco = $rs->getString($startcol + 6);

			$this->comision = $rs->getFloat($startcol + 7);

			$this->resetModified();

			$this->setNew(false);

						return $startcol + 8; 
		} catch (Exception $e) {
			throw new PropelException("Error populating Cuenta object", $e);
		}
	}

	
	public function delete($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("This object has already been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(CuentaPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			CuentaPeer::doDelete($this, $con);
			$this->setDeleted(true);
			$con->commit();
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	public function save($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("You cannot save an object that has been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(CuentaPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			$affectedRows = $this->doSave($con);
			$con->commit();
			return $affectedRows;
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	protected function doSave($con)
	{
		$affectedRows = 0; 		if (!$this->alreadyInSave) {
			$this->alreadyInSave = true;


						if ($this->isModified()) {
				if ($this->isNew()) {
					$pk = CuentaPeer::doInsert($this, $con);
					$affectedRows += 1; 										 										 
					$this->setId($pk);  
					$this->setNew(false);
				} else {
					$affectedRows += CuentaPeer::doUpdate($this, $con);
				}
				$this->resetModified(); 			}

			$this->alreadyInSave = false;
		}
		return $affectedRows;
	} 
	
	protected $validationFailures = array();

	
	public function getValidationFailures()
	{
		return $this->validationFailures;
	}

	
	public function validate($columns = null)
	{
		$res = $this->doValidate($columns);
		if ($res === true) {
			$this->validationFailures = array();
			return true;
		} else {
			$this->validationFailures = $res;
			return false;
		}
	}

	
	protected function doValidate($columns = null)
	{
		if (!$this->alreadyInValidation) {
			$this->alreadyInValidation = true;
			$retval = null;

			$failureMap = array();


			if (($retval = CuentaPeer::doValidate($this, $columns)) !== true) {
				$failureMap = array_merge($failureMap, $retval);
			}



			$this->alreadyInValidation = false;
		}

		return (!empty($failureMap) ? $failureMap : true);
	}

	
	public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = CuentaPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->getByPosition($pos);
	}

	
	public function getByPosition($pos)
	{
		switch($pos) {
			case 0:
				return $this->getId();
				break;
			case 1:
				return $this->getClienteId();
				break;
			case 2:
				return $this->getPorcComision();
				break;
			case 3:
				return $this->getDescuento();
				break;
			case 4:
				return $this->getCuenta();
				break;
			case 5:
				return $this->getSucursal();
				break;
			case 6:
				return $this->getBanco();
				break;
			case 7:
				return $this->getComision();
				break;
			default:
				return null;
				break;
		} 	}

	
	public function toArray($keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = CuentaPeer::getFieldNames($keyType);
		$result = array(
			$keys[0] => $this->getId(),
			$keys[1] => $this->getClienteId(),
			$keys[2] => $this->getPorcComision(),
			$keys[3] => $this->getDescuento(),
			$keys[4] => $this->getCuenta(),
			$keys[5] => $this->getSucursal(),
			$keys[6] => $this->getBanco(),
			$keys[7] => $this->getComision(),
		);
		return $result;
	}

	
	public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = CuentaPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->setByPosition($pos, $value);
	}

	
	public function setByPosition($pos, $value)
	{
		switch($pos) {
			case 0:
				$this->setId($value);
				break;
			case 1:
				$this->setClienteId($value);
				break;
			case 2:
				$this->setPorcComision($value);
				break;
			case 3:
				$this->setDescuento($value);
				break;
			case 4:
				$this->setCuenta($value);
				break;
			case 5:
				$this->setSucursal($value);
				break;
			case 6:
				$this->setBanco($value);
				break;
			case 7:
				$this->setComision($value);
				break;
		} 	}

	
	public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = CuentaPeer::getFieldNames($keyType);

		if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]);
		if (array_key_exists($keys[1], $arr)) $this->setClienteId($arr[$keys[1]]);
		if (array_key_exists($keys[2], $arr)) $this->setPorcComision($arr[$keys[2]]);
		if (array_key_exists($keys[3], $arr)) $this->setDescuento($arr[$keys[3]]);
		if (array_key_exists($keys[4], $arr)) $this->setCuenta($arr[$keys[4]]);
		if (array_key_exists($keys[5], $arr)) $this->setSucursal($arr[$keys[5]]);
		if (array_key_exists($keys[6], $arr)) $this->setBanco($arr[$keys[6]]);
		if (array_key_exists($keys[7], $arr)) $this->setComision($arr[$keys[7]]);
	}

	
	public function buildCriteria()
	{
		$criteria = new Criteria(CuentaPeer::DATABASE_NAME);

		if ($this->isColumnModified(CuentaPeer::ID)) $criteria->add(CuentaPeer::ID, $this->id);
		if ($this->isColumnModified(CuentaPeer::CLIENTE_ID)) $criteria->add(CuentaPeer::CLIENTE_ID, $this->cliente_id);
		if ($this->isColumnModified(CuentaPeer::PORC_COMISION)) $criteria->add(CuentaPeer::PORC_COMISION, $this->porc_comision);
		if ($this->isColumnModified(CuentaPeer::DESCUENTO)) $criteria->add(CuentaPeer::DESCUENTO, $this->descuento);
		if ($this->isColumnModified(CuentaPeer::CUENTA)) $criteria->add(CuentaPeer::CUENTA, $this->cuenta);
		if ($this->isColumnModified(CuentaPeer::SUCURSAL)) $criteria->add(CuentaPeer::SUCURSAL, $this->sucursal);
		if ($this->isColumnModified(CuentaPeer::BANCO)) $criteria->add(CuentaPeer::BANCO, $this->banco);
		if ($this->isColumnModified(CuentaPeer::COMISION)) $criteria->add(CuentaPeer::COMISION, $this->comision);

		return $criteria;
	}

	
	public function buildPkeyCriteria()
	{
		$criteria = new Criteria(CuentaPeer::DATABASE_NAME);

		$criteria->add(CuentaPeer::ID, $this->id);

		return $criteria;
	}

	
	public function getPrimaryKey()
	{
		return $this->getId();
	}

	
	public function setPrimaryKey($key)
	{
		$this->setId($key);
	}

	
	public function copyInto($copyObj, $deepCopy = false)
	{

		$copyObj->setClienteId($this->cliente_id);

		$copyObj->setPorcComision($this->porc_comision);

		$copyObj->setDescuento($this->descuento);

		$copyObj->setCuenta($this->cuenta);

		$copyObj->setSucursal($this->sucursal);

		$copyObj->setBanco($this->banco);

		$copyObj->setComision($this->comision);


		$copyObj->setNew(true);

		$copyObj->setId(NULL); 
	}

	
	public function copy($deepCopy = false)
	{
				$clazz = get_class($this);
		$copyObj = new $clazz();
		$this->copyInto($copyObj, $deepCopy);
		return $copyObj;
	}

	
	public function getPeer()
	{
		if (self::$peer === null) {
			self::$peer = new CuentaPeer();
		}
		return self::$peer;
	}

} 